#import "BWColorKey.h"

// scaffolding
#import "BWGraphDocument.h"

@implementation BWColorKey

+ (void) initialize
{
    [super initialize];

    [BWColorKey setVersion: 1];

} // initalize


- (id) init
{
    if (self = [super init]) {
        threads = [[NSMutableArray alloc] init];
    }

    return (self);

} // init


- (void) dealloc
{
    [threads release];
    [super dealloc];

} // dealloc


- (void) addThread: (BWThread *) thread
{
    [threads addObject: thread];
} // addThread


- (void) setDocument: (BWGraphDocument *) d
{
    document = d;
} // setDocument


// KVC accessors

- (unsigned int) countOfThreads
{
    return ([threads count]);
} // countOfThreads


- (id) objectInThreadsAtIndex: (unsigned int) index
{
    return ([threads objectAtIndex: index]);
} // objectInThreadsAtIndex


- (void) insertObject: (id) object inThreadsAtIndex: (unsigned int) index
{
    [threads insertObject: object
             atIndex: index];
    [document redraw];
} // insertObject


- (void) removeObjectFromThreadsAtIndex: (unsigned int) index
{
    [threads removeObjectAtIndex: index];
    [document redraw];
} // removeObjectFromThreadsAtIndex


- (void) replaceObjectInThreadsAtIndex: (unsigned int) index
                            withObject: (id) object
{
    [threads replaceObjectAtIndex: index  withObject: object];
    [document redraw];
} // replaceObjectInThreadsAtIndex


- (NSArray *) threadArrayThingie
{
    return (threads);
} // threadArrayThingie


- (BWThread *) colorAtIndex: (int) row
{
    BWThread *thread = [threads objectAtIndex: row];
    return (thread);
    
} // colorAtIndex


- (void) encodeWithCoder: (NSCoder *) coder
{
    [coder encodeObject: threads];
    
} // encodeWithCoder



- (id) initWithCoder: (NSCoder *) coder
{
    if (self = [super init]) {
        [threads release];
        threads = [coder decodeObject];
        [threads retain];
    }

    return (self);

} // coder

@end // BWColorKey

